//lazy-路由懒加载（是个函数）
//Suspense-请求懒加载时路由组件还未返回时展示的组件
import React, {Component, lazy, Suspense} from 'react';
import {NavLink, Route} from "react-router-dom";
// import About from "./pages/About";
// import Home from "./pages/Home";
//请求懒加载时路由组件还未返回时展示的组件-此时必须用import
import Loading from "./components/Loading";
//路由懒加载
const About = lazy(() => import('./pages/About'))
const Home = lazy(() => import('./pages/Home'))

class App extends Component {
    render() {
        return (
            <div>
                <div className="row">
                    <div className="col-xs-offset-2 col-xs-8">
                        <div className="page-header"><h2>React Router Demo</h2></div>
                    </div>
                </div>
                <div className="row">
                    <div className="col-xs-2 col-xs-offset-2">
                        <div className="list-group">
                            <NavLink activeClassName='activeOrange' className="list-group-item"
                                     to='/about'>About</NavLink>
                            <NavLink activeClassName='activeOrange' className="list-group-item"
                                     to='/home'>Home</NavLink>
                            {/*<a className="list-group-item active" href="./about.html">About</a>*/}
                            {/*<a className="list-group-item" href="./home.html">Home</a>*/}
                        </div>
                    </div>
                    <div className="col-xs-6">
                        <div className="panel">
                            <div className="panel-body">
                                <Suspense fallback={<Loading/>}>
                                    {/*<h3>我是About的内容</h3>*/}
                                    <Route path='/about' component={About}/>
                                    <Route path='/home' component={Home}/>
                                </Suspense>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        );
    }
}

export default App;